package com.sloth.bear.controller;

import com.sloth.bear.dto.request.NameSpaceRequest;
import com.sloth.bear.dto.vo.NameSpaceVo;
import com.sloth.bear.service.NameSpaceService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 命名空间管理
 */
@RestController
@RequestMapping("/namespace")
@RequiredArgsConstructor
public class NameSpaceController {

    private final NameSpaceService nameSpaceService;

    /**
     * 创建命名空间
     */
    @PostMapping
    public NameSpaceVo createSpace(@Valid @RequestBody NameSpaceRequest request) {
        return nameSpaceService.createSpace(request);
    }

    /**
     * 获取所有命名空间
     */
    @GetMapping("/list")
    public List<NameSpaceVo> getAllSpaces() {
        return nameSpaceService.getAllSpaces();
    }

    /**
     * 根据ID获取命名空间详情
     */
    @GetMapping("/{id}")
    public NameSpaceVo getSpaceById(@PathVariable Long id) {
        return nameSpaceService.getSpaceById(id);
    }

    /**
     * 更新命名空间
     */
    @PutMapping("/{id}")
    public NameSpaceVo updateSpace(@PathVariable Long id, @Valid @RequestBody NameSpaceRequest request) {
        return nameSpaceService.updateSpace(id, request);
    }

    /**
     * 删除命名空间
     */
    @DeleteMapping("/{id}")
    public boolean deleteSpace(@PathVariable Long id) {
        return nameSpaceService.deleteSpace(id);
    }
}